package com.qdsg.ysg.doctor.ui.fragment;//package com.qdsg.ysg.doctor.ui.fragment;
//
//import android.content.Context;
//import android.content.SharedPreferences;
//import android.graphics.Canvas;
//import android.graphics.Rect;
//import android.os.Bundle;
//import android.support.v7.widget.LinearLayoutManager;
//import android.support.v7.widget.RecyclerView;
//import android.text.TextUtils;
//import android.util.Log;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.ViewGroup;
//import android.widget.TextView;
//import android.widget.Toast;
//
//import com.chinamobile.ysx.YSXInstantMeetingOptions;
//import com.chinamobile.ysx.YSXJoinMeetingOptions;
//import com.chinamobile.ysx.YSXMeetingService;
//import com.chinamobile.ysx.YSXSdk;
//import com.rest.business.RestProxy;
//import com.rest.exception.BusinessException;
//import com.rest.response.BaseResponse;
//import com.rest.response.ConsulationResponse;
//import com.rest.response.MeetingResponse;
//import com.rest.response.Patient;
//import com.scwang.smartrefresh.layout.api.RefreshLayout;
//import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
//import com.scwang.smartrefresh.layout.footer.BallPulseFooter;
//import com.scwang.smartrefresh.layout.header.ClassicsHeader;
//import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
//import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import butterknife.BindView;
//import butterknife.OnClick;
//import io.reactivex.Observer;
//import io.reactivex.disposables.Disposable;
//import jz.joyoung.robot.util.PreferencesHelper;
//import com.qdsg.ysg.doctor.R;
//import com.qdsg.ysg.doctor.base.BaseApplication;
//import com.qdsg.ysg.doctor.base.BaseFragment;
//import com.qdsg.ysg.doctor.ui.AddReferralActivity;
//import com.qdsg.ysg.doctor.ui.PatientDetailActivity;
//
///**
// * Created by Administrator on 2018/5/25.
// */
//
//public class VideoConsultationFragment extends BaseFragment {
//    private static VideoConsultationFragment consultationFragment;
//
//    @BindView(R.id.refreshLayout)
//    RefreshLayout refreshLayout;
//    @BindView(R.id.recyclerView)
//    RecyclerView recyclerView;
//    @BindView(R.id.btn_consultation)
//    TextView btn_consultation;
//    @BindView(R.id.tv_title)
//    TextView tv_title;
//
//    MyAdapter adapter;
//
//    List<Patient> list = new ArrayList<>();
//
//    public static VideoConsultationFragment newInstance() {
//        if (consultationFragment == null) {
//            consultationFragment = new VideoConsultationFragment();
//            return consultationFragment;
//        } else {
//            return consultationFragment;
//        }
//    }
//
//    @Override
//    protected int getLayoutResource() {
//        return R.layout.fragment_consultation;
//    }
//
//    @Override
//    protected void initView() {
//        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
//        manager.setOrientation(LinearLayoutManager.VERTICAL);
//        recyclerView.setLayoutManager(manager);
//        adapter = new MyAdapter();
//        recyclerView.setAdapter(adapter);
//        recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
//            @Override
//            public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
//                super.onDraw(c, parent, state);
//            }
//
//            @Override
//            public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
//                super.getItemOffsets(outRect, view, parent, state);
//                outRect.bottom = 1;
//            }
//        });
//        refreshLayout.setRefreshFooter(new BallPulseFooter(getActivity()).setSpinnerStyle(SpinnerStyle.Scale));
//        refreshLayout.setRefreshHeader(new ClassicsHeader(getActivity()));
//        refreshLayout.setEnableLoadMore(false);
//        refreshLayout.setOnRefreshListener(new OnRefreshListener() {
//            @Override
//            public void onRefresh(RefreshLayout refreshlayout) {
//                getVideoConsultationList();
//            }
//        });
//        refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
//            @Override
//            public void onLoadMore(RefreshLayout refreshlayout) {
//
//            }
//        });
//        if (BaseApplication.userType == 1) {
//            btn_consultation.setVisibility(View.VISIBLE);
//        } else if (BaseApplication.userType == 2) {
//            btn_consultation.setVisibility(View.GONE);
//        }
//        tv_title.setText("视频会诊");
//    }
//
//    @Override
//    protected void initData() {
////        if (BaseApplication.userType == 1) {
////            getConsultationBaseList();
////        } else if (BaseApplication.userType == 2) {
////            getConsultationProList();
////        }
//    }
//
//    class MyAdapter extends RecyclerView.Adapter<MyAdapter.Holder> {
//
//        @Override
//        public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
//            MyAdapter.Holder myHolder = new MyAdapter.Holder(LayoutInflater.from(getActivity()).inflate(R.layout.item_consultation, parent, false));
//            return myHolder;
//        }
//
//        @Override
//        public void onBindViewHolder(Holder holder, final int position) {
//            holder.itemView.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    Bundle bundle = new Bundle();
//                    bundle.putInt("type", 1);
//                    bundle.putSerializable("obj", list.get(position));
//                    startActivity(PatientDetailActivity.class, bundle);
//                }
//            });
//            holder.tv_reason.setText(list.get(position).medhisZs);
//            holder.tv_time.setText(list.get(position).createDate);
//            holder.tv_patient_name.setText(list.get(position).patientName);
//            holder.tv_hint.setText(list.get(position).getHint());
//            holder.tv_patient_age.setText(list.get(position).getAge());
//            holder.tv_patient_gender.setText(list.get(position).patientSex);
//            if(BaseApplication.userType == 1){
//                holder.tv_hospita_name.setText("预约医院");
//                holder.tv_hospital.setText(list.get(position).receiveHosAndDocNames);
//            }else{
//                holder.tv_hospita_name.setText("申请医院");
//                holder.tv_hospital.setText(list.get(position).initialHosAndDocNames);
//            }
//
//
//            if (BaseApplication.userType == 2) {
//                holder.button1.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        if (list.get(position).flag == 1) {
//                            editDoctorStatus(list.get(position).diagnoseId, "0");
//                        } else if (list.get(position).flag == 2){
//                            getMeeting(list.get(position).diagnoseId);
//                        }
//                    }
//                });
//                holder.button2.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        editDoctorStatus(list.get(position).diagnoseId, "4");
//                    }
//                });
//
//
//                switch (list.get(position).flag) {
//                    case 1:
//                        holder.button1.setText("拒绝");
//                        holder.button2.setText("接受");
//                        holder.button3.setText("查看详情");
//                        holder.button1.setVisibility(View.VISIBLE);
//                        holder.button2.setVisibility(View.VISIBLE);
//                        holder.button3.setVisibility(View.VISIBLE);
////                        holder.button1.setOnClickListener(new View.OnClickListener() {
////                            @Override
////                            public void onClick(View v) {
////                                editDoctorStatus(list.get(position).diagnoseId, "0");
////                            }
////                        });
////                        holder.button2.setOnClickListener(new View.OnClickListener() {
////                            @Override
////                            public void onClick(View v) {
////                                editDoctorStatus(list.get(position).diagnoseId, "4");
////                            }
////                        });
//                        break;
//                    case 2:
//                        holder.button1.setText("开始会诊");
//                        holder.button1.setTextColor(getResources().getColor(R.color.mainGreen));
//                        holder.button1.setBackgroundResource(R.drawable.item_bg_green_circle);
//                        holder.button2.setText("查看详情");
//                        holder.button1.setVisibility(View.VISIBLE);
//                        holder.button2.setVisibility(View.VISIBLE);
//                        holder.button3.setVisibility(View.GONE);
////                        holder.button1.setOnClickListener(new View.OnClickListener() {
////                            @Override
////                            public void onClick(View v) {
////                                getMeeting(list.get(position).diagnoseId);
////                            }
////                        });
//                        break;
//                }
//            } else {
//                holder.button1.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        if (list.get(position).flag == 1) {
//                            Bundle bundle = new Bundle();
//                            bundle.putSerializable("diagnoseId", list.get(position));
//                            bundle.putInt("type", 3);
//                            startActivity(AddReferralActivity.class, bundle);
//                        } else if (list.get(position).flag == 2) {
//                            getMeeting(list.get(position).diagnoseId);
//                        }
//                    }
//                });
//                holder.button2.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        Bundle bundle = new Bundle();
//                        bundle.putSerializable("diagnoseId", list.get(position));
//                        bundle.putInt("type", 3);
//                        startActivity(AddReferralActivity.class, bundle);
//                    }
//                });
//
//
//                switch (list.get(position).flag) {
//                    case 1:
//                        holder.button1.setText("编辑");
//                        holder.button1.setTextColor(getResources().getColor(R.color.commonGrey));
//                        holder.button1.setBackgroundResource(R.drawable.item_bg_grey);
//                        holder.button1.setVisibility(View.VISIBLE);
//                        holder.button2.setVisibility(View.GONE);
//                        holder.button3.setVisibility(View.GONE);
////                        holder.button1.setOnClickListener(new View.OnClickListener() {
////                            @Override
////                            public void onClick(View v) {
////                                Bundle bundle = new Bundle();
////                                bundle.putSerializable("diagnoseId", list.get(position));
////                                bundle.putInt("type", 3);
////                                startActivity(AddReferralActivity.class, bundle);
////                            }
////                        });
//                        break;
//                    case 2:
//                        holder.button1.setText("开始会诊");
//                        holder.button1.setTextColor(getResources().getColor(R.color.mainGreen));
//                        holder.button1.setBackgroundResource(R.drawable.item_bg_green_circle);
//                        holder.button2.setText("编辑");
//                        holder.button1.setVisibility(View.VISIBLE);
//                        holder.button2.setVisibility(View.VISIBLE);
//                        holder.button3.setVisibility(View.GONE);
////                        holder.button2.setOnClickListener(new View.OnClickListener() {
////                            @Override
////                            public void onClick(View v) {
////                                Bundle bundle = new Bundle();
////                                bundle.putSerializable("diagnoseId", list.get(position));
////                                bundle.putInt("type", 3);
////                                startActivity(AddReferralActivity.class, bundle);
////                            }
////                        });
////                        holder.button1.setOnClickListener(new View.OnClickListener() {
////                            @Override
////                            public void onClick(View v) {
////                                getMeeting(list.get(position).diagnoseId);
////                            }
////                        });
//                }
//            }
//
//
//        }
//
//        @Override
//        public int getItemCount() {
//            return list.size();
//        }
//
//        class Holder extends RecyclerView.ViewHolder {
//
//            TextView tv_reason, tv_time, tv_id_card, tv_patient_name, tv_hint, tv_patient_gender, tv_patient_age, tv_hospital, button1, button2, button3,tv_hospita_name;
//
//            public Holder(View itemView) {
//                super(itemView);
//                tv_reason = itemView.findViewById(R.id.tv_reason);
//                tv_time = itemView.findViewById(R.id.tv_time);
//                tv_id_card = itemView.findViewById(R.id.tv_id_card);
//                tv_patient_name = itemView.findViewById(R.id.tv_patient_name);
//                tv_hint = itemView.findViewById(R.id.tv_hint);
//                tv_patient_gender = itemView.findViewById(R.id.tv_patient_gender);
//                tv_patient_age = itemView.findViewById(R.id.tv_patient_age);
//                tv_hospital = itemView.findViewById(R.id.tv_hospital);
//                button1 = itemView.findViewById(R.id.button1);
//                button2 = itemView.findViewById(R.id.button2);
//                button3 = itemView.findViewById(R.id.button3);
//                tv_hospita_name = itemView.findViewById(R.id.tv_hospita_name);
//            }
//        }
//
//    }
//
//    @Override
//    public void onResume() {
//        getVideoConsultationList();
//        super.onResume();
//    }
//
//    @OnClick(R.id.btn_consultation)
//    void btn_consultation() {
//        Bundle bundle = new Bundle();
//        bundle.putInt("type", 1);
//        startActivity(AddReferralActivity.class, bundle);
//    }
//
//
//    private void getVideoConsultationList() {
//        RestProxy.getInstance().getConsultationList(1 + "", 50 + "", 1 + "", "102", new Observer<ConsulationResponse>() {
//            @Override
//            public void onSubscribe(Disposable d) {
//
//            }
//
//            @Override
//            public void onNext(ConsulationResponse consulationResponse) {
//                list.clear();
//                list.addAll(consulationResponse.data.records);
//                adapter.notifyDataSetChanged();
//            }
//
//            @Override
//            public void onError(Throwable e) {
//                refreshLayout.finishLoadMore(true/*,false*/);//传入false表示加载失败
//                refreshLayout.finishRefresh(true/*,false*/);//传入false表示加载失败
//            }
//
//            @Override
//            public void onComplete() {
//                refreshLayout.finishLoadMore(true/*,false*/);//传入false表示加载失败
//                refreshLayout.finishRefresh(true/*,false*/);//传入false表示加载失败
//            }
//        });
//    }
//
//
//    private void editDoctorStatus(String diagnoseId, String flag) {
//        RestProxy.getInstance().editDoctorStatus(diagnoseId, flag, new Observer<BaseResponse>() {
//            @Override
//            public void onSubscribe(Disposable d) {
//
//            }
//
//            @Override
//            public void onNext(BaseResponse baseResponse) {
//                getVideoConsultationList();
//            }
//
//            @Override
//            public void onError(Throwable e) {
//                if (e instanceof BusinessException) {
//                    Toast.makeText(getActivity(), ((BusinessException) e).errorDescription, Toast.LENGTH_SHORT).show();
//                }
//            }
//
//            @Override
//            public void onComplete() {
//
//            }
//        });
//    }
//
//
//    public void onClickBtnJoinMeeting(String meetingNo) {
//
//        if (meetingNo.length() == 0) {
//            Toast.makeText(getActivity(), "You need to enter a meeting number which you want to join.", Toast.LENGTH_LONG).show();
//            return;
//        }
//
//        YSXSdk sdk = YSXSdk.getInstance();
//
//        if (!sdk.isInitialized()) {
//            Toast.makeText(getActivity(), "ysxSDK has not been initialized successfully", Toast.LENGTH_LONG).show();
//            return;
//        }
//
//        YSXMeetingService meetingService = sdk.getMeetingService();
//
//        YSXJoinMeetingOptions opts = new YSXJoinMeetingOptions();
////		opts.no_driving_mode = true;
////        opts.no_invite = true;
////		opts.no_meeting_end_message = true;
////		opts.no_titlebar = true;
////		opts.no_bottom_toolbar = true;
////		opts.no_dial_in_via_phone = true;
////		opts.no_dial_out_to_phone = true;
//        opts.no_disconnect_audio = true;
////		opts.no_share = true;
////		opts.invite_options = YSXInviteOptions.INVITE_VIA_EMAIL + YSXInviteOptions.INVITE_VIA_SMS;
////		opts.meeting_views_options = YSXMeetingViewsOptions.NO_BUTTON_SHARE;
//        opts.no_audio = false;
//        opts.no_video = false;
////		opts.no_meeting_error_message = true;
////		opts.participant_id = "participant id";
//
//        int ret = meetingService.joinMeeting(getActivity(), meetingNo, "test", "", opts);
//
//        Log.i("", "onClickBtnJoinMeeting, ret=" + ret);
//    }
//
//    private void getMeeting(final String diagnoseId) {
//        RestProxy.getInstance().getMeeting(diagnoseId, new Observer<MeetingResponse>() {
//            @Override
//            public void onSubscribe(Disposable d) {
//
//            }
//
//            @Override
//            public void onNext(MeetingResponse meetingResponse) {
//                if (!TextUtils.isEmpty(meetingResponse.data.meetingId)) {
//                    onClickBtnJoinMeeting(meetingResponse.data.meetingId + "");
//                } else {
//                    YSXInstantMeetingOptions opts = new YSXInstantMeetingOptions();
//                    opts.no_driving_mode = true;
//                    YSXSdk sdk1 = YSXSdk.getInstance();
//                    YSXMeetingService meetingservice1 = sdk1.getMeetingService();
//                    String tokensaved = PreferencesHelper.getInstance().getString(getActivity(), "sdkToken");
//                    if (tokensaved != null && !tokensaved.equals("")) {
//                        //通过保存的 token起会
//                        String userid = YSXSdk.getInstance().getYSXuser().getUserId();
//                        int ret = meetingservice1.startInstantMeeting(getActivity(), userid, tokensaved, 99, "test", opts);
//                    } else {
//                        //登录状态的用户直接起会
//                        int ret = meetingservice1.startInstantMeeting(getActivity(), opts);
//                    }
//                    BaseApplication.currentDiagnoseId = diagnoseId;
//                }
//            }
//
//            @Override
//            public void onError(Throwable e) {
//
//            }
//
//            @Override
//            public void onComplete() {
//
//            }
//        });
//    }
//
//}
